<template>
	<view class="main">
		<view class="head" style="margin-bottom: 30rpx;">
			<!-- <image :src="info.avatar"></image> -->
			<view>{{info.name}}</view>
		</view>
		<image :src="'https://suoke.jiugezixun.cn'+info.weixin_qrcode" :show-menu-by-longpress="true" mode="widthFix" class="code"></image>
		<view class="tips">
			长按识别上方二维码图案
		</view>
		<!-- <u-button @click="toLogin">登陆</u-button> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				info:{
					name:'',
					weixin_qrcode:''
				},
				obj:{}

			};
		},
		onLoad(options) {
			let id = options.id
			let that = this
			uni.request({
				url: 'https://suoke.jiugezixun.cn/index.php/api/person/detail',
				data: {
					id: id
				},
				method: 'POST',
				header: {
					'content-type': 'application/x-www-form-urlencoded',
					'X-Requested-With': 'XMLHttpRequest'
				},
				success: result => {
					let datas = result.data
					console.log(datas)
					if (datas.code == 1) {
						that.info = datas.data
					} else {
						uni.showToast({
							title: datas.msg,
							icon: 'error'
						})
					}

				},
				fail: result => {
					uni.showModal({
						title: '网络错误',
						content: '网络出错，请刷新重试',
						showCancel: false
					})
				}
			})
		},
		methods:{
			toLogin(){
				let that = this
				uni.getUserInfo({
					desc: '登录的数据',
					success(ures) {
						console.log(ures, '返回的用户信息');
						uni.login({
							provider: 'wechat',
							success: function(res) {
								console.log('微信登录成功', res)
								let obj = {
									code: res.code,
									encryptedData: ures.encryptedData,
									iv: ures.iv
								}
								that.obj = obj
								that.wxAppLogin()
							},
							fail: function(err) {
								console.log('微信登录失败', err)
							}
						})
					}
				})
			},
			wxAppLogin(){
				let that = this
				uni.request({
					url: 'http://hcqsuoke.cn/index.php/api/wechat/minilogin',
					data: that.obj,
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'X-Requested-With': 'XMLHttpRequest'
					},
					success: result => {
						let datas = result.data
						if (datas.code == 1) {
						} else {
							uni.showToast({
								title: datas.msg,
								icon: 'error'
							})
						}
				
					},
					fail: result => {
						uni.showModal({
							title: '网络错误',
							content: '网络出错，请刷新重试',
							showCancel: false
						})
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	/* pages/page/index.wxss */
	.main {
		background: white;
		margin: 50rpx 30rpx;
		box-shadow: 1rpx 1rpx 10rpx 1rpx rgb(218, 186, 248);
		padding: 30rpx 40rpx;
		border-radius: 10rpx;
	}

	.head {
		display: flex;
		align-items: center;
	}

	.head image {
		width: 80rpx;
		height: 80rpx;
		margin-right: 20rpx;
	}

	.code {
		width: 100%;
		height: 200rpx;
		margin: 20rpx 0;
		display: block;

	}

	.tips {
		text-align: center;
		font-size: 24rpx;
		color: grey;
	}
</style>